﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace TUM.Mustertexte_Parser
{
    public class ProductTopic : TemplateTopic
    {
        public ProductTopic[] SubTopics
        {
            get
            {
                if (_SubTopics == null)
                    LoadSubTopics();
                return _SubTopics;
            }
        }
        private ProductTopic[] _SubTopics;


        internal ProductTopic(string templateFilePath, XmlNode topicNode)
            : base(templateFilePath, topicNode)
        {
        }

        public ProductTopic GetSubTopicByName(string topicName)
        {
            foreach (ProductTopic curSubTopic in SubTopics)
            {
                if (curSubTopic.Name.Equals(topicName, StringComparison.OrdinalIgnoreCase))
                    return curSubTopic;
            }
            return null;
        }


        private void LoadSubTopics()
        {
            var subTopicNodes = TopicNode.SelectNodes("Themenmuster");
            _SubTopics = new ProductTopic[subTopicNodes.Count];
            int a = 0;

            foreach (XmlNode curSubTopicNode in subTopicNodes)
            {
                _SubTopics[a] = new ProductTopic(TemplateFilePath, curSubTopicNode);
                a++;
            }
        }
    }
}
